/*
 * Created on 03.05.2006
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package ro.qi.framework.sys.users.profile.entities;

/**
 * @author Luiza Varovici
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
import java.util.Hashtable;
import java.util.Vector;

import ro.qi.framework.sys.entities.Entity;

/**
 * @author Denverash
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class UsersAccountProfileGroupCollection extends Entity {

	public UsersAccountProfileGroupCollection() {
		super();
		select();
	}

	public int getNoGroups() {
		return ((Vector)getValue("groups")).size();
	}
	
	public int getGroupId(int index) {
		if( index < getNoGroups() ) {
			Hashtable tmp = (Hashtable)(((Vector)getValue("groups")).get(index));
			if( tmp.containsKey("groupId") )
				return Integer.parseInt(tmp.get("groupId").toString());
		}
		return 0;
	}
	
	public UsersAccountProfileGroup getGroup(int index) {
		int groupId = getGroupId(index);
		if( groupId > 0 )
			return new UsersAccountProfileGroup(groupId);
		return null;
	}

	public UsersAccountProfileGroup getFirstGroup() {
		if( getNoGroups() > 0 ) {
			UsersAccountProfileGroup group = getGroup(0);
			while( group.getPrevId() > 0 )
				group = new UsersAccountProfileGroup(group.getPrevId());
			return group;
		}
		return null;
	}

	public UsersAccountProfileGroup getLastGroup() {
		if( getNoGroups() > 0 ) {
			UsersAccountProfileGroup group = getGroup(0);
			while( group.getNextId() > 0 )
				group = new UsersAccountProfileGroup(group.getNextId());
			return group;
		}
		return null;
	}

}

